#pragma once

#include "HashedString.h"
#include "IEvent.h"
#include "TinyXML2.h"
#include "Entity.h"

class EntityController;

class PlayerBehavior
{
public:
	const HashedString& Type() const;
	PlayerBehavior( EntityController* controller );

	void Update();
	
	bool OnMouseLeftDown( IEvent& event );
	bool OnMouseRightDown( IEvent& event );
	bool OnKeyPress( IEvent& event );
	bool Destination( IEvent& event );
	bool DestinationReached( IEvent& event );
	bool AddDestination( IEvent& event );

	
	HashedString EnemyGroup();
	HashedString Group();
	void EnemyGroup( HashedString& group );
	void Group( HashedString& group );

	Entity* FindClosestEnemy();
	void DoAutoAttack();

	bool ToXML( tinyxml2::XMLPrinter& printer );
	bool FromXML( tinyxml2::XMLElement* element );
protected:
	enum MouseState
	{
		ATTACK_MOVE = 0,
		SELECTION = 1,
	};

	enum State
	{
		DEFAULT = 0,
		AUTO_ATTACKING = 1,
		FOLLOWING = 2,
	};

	MouseState m_mouseState;
	State m_state;
	bool m_autoAttackFlag;

	EntityController* m_controller;

	HashedString m_enemyGroup;
	HashedString m_group;

	Entity* m_followingEntity;
	Entity* m_engagedEnemy;
	Entity* m_selected;

	Time m_lastMoveTime;
	Time m_lastPathTime;
	Time m_lastAutoAttackTime;
};